<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h2>模板使用</h2>
    <hr>
    <h3>变量</h3>
    <p>name:{{ name }}</p>
    <p>age:{{ age }}</p>
    <p>likes:{{ likes }}</p>
    <p>likes.1:{{ likes.1 }}</p>
    <p>address:{{ address }}</p>
    <p>address.city:{{ address.city }}</p>

    <hr>
    <h3>if语句</h3>
    <h4>if单分支</h4>
    {% if age < 18 %}
        <p>{{ name }} 未成年</p>
    {% endif %}

    <h4>if双分支</h4>
    {% if age < 18 %}
        <p>{{ name }} 未成年</p>
    {% else %}
        <p>{{ name }} 成年</p>
    {% endif %}

    <h4>if多分支</h4>
    {% if age < 18 %}
        <p>{{ name }} 未成年</p>
    {% elif age < 60 %}
        <p>{{ name }} 壮年</p>
    {% else %}
        <p>{{ name }} 老年</p>
    {% endif %}

    <h4>结合运算符</h4>
    {% if age >= 18 and age < 60 %}
        <p>{{ name }} 壮年</p>
    {% endif %}

    {% if '电影' in likes %}
        <p>{{ name }} 喜欢电影</p>
    {% endif %}

    <hr>
    <h3>for语句</h3>
    <h4>正常</h4>
    {% for like in likes %}
        <p>{{ like }}</p>
    {% endfor %}

    <h4>为空</h4>
    {% for like in likes2 %}
        <p>{{ like }}</p>
    {% empty %}
        <p>likes2为空或不存在</p>
    {% endfor %}

    <h4>下标counter</h4>
    {% for like in likes %}
        <p>
            counter0: {{ forloop.counter0 }}{# 从0开始 #}
            counter: {{ forloop.counter }}{# 从1开始 #}
            revcounter0: {{ forloop.revcounter0 }}{# 到0 #}
            revcounter: {{ forloop.revcounter }}{# 到1 #}

            {% if forloop.first %}
            	<b> - first</b>
            {% endif %}
            {% if forloop.last %}
            	<b> - last</b>
            {% endif %}
        </p>
    {% endfor %}

    <h4>循环嵌套</h4>
    <table border="1" width="300">
        {% for star in stars %}
            <tr>
                {% for s in star %}
                    <td>
                        {{ s }} - {{ forloop.parentloop.counter }} - {{ forloop.counter }}
                    </td>
                {% endfor %}
            </tr>
        {% endfor %}
    </table>

    <hr>
    <h3>过滤器</h3>
    <h4>正常</h4>
    <p>age={{ age }}</p>
    <p>age|add:2={{ age|add:2 }}</p>
    <p>age|add:-2={{ age|add:-2 }}</p>

    <p>name={{ name }}</p>
    <p>name|first|lower={{ name|first|lower }}</p>
    <p>name|last|upper={{ name|last|upper }}</p>
    <p>name1|title={{ name1|title }}</p>
    <p>name1|truncatechars:3={{ name1|truncatechars:4 }}</p>
    <p>likes|join:'+' = {{ likes|join:'+' }}</p>
    <p>likes2|default:'swim' = {{ likes2|default:'swim' }}</p>
    <p>birth = {{ birth }}</p>
    <p>birth = {{ birth|date:'y-m-d' }}</p>
    <p>html解析 = {{ html }}</p>
    <p>解析html|safe = {{ html|safe }}</p>

</body>
</html>